package Class类和反射;

import java.lang.reflect.Method;

public class Example_03 {
    static void staticMethod() {
        System.out.println("执行staticMethod()方法");
    }
    public int publicMethod(int i) {
        System.out.println("执行publicMethod()方法");
        return i * 100;
    }

    protected int protectedMethod(String s, int i)
        throws NumberFormatException {
        System.out.println("执行protectedMethod()方法");
        return Integer.parseInt(s) + i;
    }

    private String privateMethod(String...Strings) {
        System.out.println("执行privateMethod()方法");
        StringBuffer stringBuffer = new StringBuffer();
        for (String string : Strings) {
            stringBuffer.append(string);
        }
        return stringBuffer.toString();
    }

    public static void main(String[] args) {
        Example_03 example = new Example_03();
        Class exampleC = example.getClass();
        Method[] declaredMethods = exampleC.getDeclaredMethods();
        for (Method method: declaredMethods) {
            System.out.println("名称为：" + method.getName());
            System.out.println("是否允许带有可变数量的参数:" + method.isVarArgs());
            System.out.println("入口参数类型依次为：");
            // 获取所有的参数类型
            Class[] parameterTypes = method.getParameterTypes();
            for (Class parameterType: parameterTypes) {
                System.out.println(" " + parameterType);
            }
            // 获取方法返回值类型
            System.out.println("返回值类型为:" + method.getReturnType());
            System.out.println("可能抛出的异常类型有：");
            Class[] exceptionTypes = method.getExceptionTypes();
            for (Class exceptionType : exceptionTypes) {
                System.out.println(" " + exceptionType);
            }
        }
    }
}
